+#!/bin/sh
+
+#ROOT=/usr/share/garradin/www
+ROOT=${0%/*}/www
+#ROOT=~/fossil/garradin/src/www
+ROUTER=${ROOT}/_route.php
+PORT=8088
+ADDRESS=localhost
+VERBOSE=0
+
+# Execute getopt
+ARGS=`getopt -o "p:vh" -l "port:,verbose,help" -n "garradin" -- "$@"`
+
+# Bad arguments
+if [ $? -ne 0 ];
+then
+ exit 1
+fi
+
+# A little magic
+eval set -- "$ARGS"
+
+# Now go through all the options
+while true;
+do
+ case "$1" in
+ -p|--port)
+ PORT=$2
+ shift;;
+
+ -v|--verbose)
+ VERBOSE=1
+ shift;;
+
+ -h|--help)
+ cat <<EOF
+Usage : $0 [COMMANDE] [PROJET]
+
+Où COMMANDE peut être :
+
+ server [-p|--port PORT]
+ Démarre un serveur web Garradin sur le port spécifié
+ (ou sur le port 8000 par défaut)
+
+ ui [-p|--port PORT]
+ Idem que 'server' mais démarre ensuite le navigateur web par défaut
+ et connecte automatiquement avec le premier administrateur
+ de l'association.
+
+Si aucune COMMANDE n'est donnée, Garradin utilisera 'ui' par défaut.
+
+PROJET est le chemin menant à un projet Garradin précis
+ (fichier .garradin.sqlite). Si aucun projet n'est indiqué, le
+ dernier projet ouvert sera rouvert. Si aucun projet n'a jamais été
+ ouvert un nouveau projet sera créé.
+
+Options :
+
+ -p|--port PORT
+ Spécifie le port pour le mode ui ou le mode serveur.
+
+ -v|--verbose
+ Affiche les requêtes reçues sur le serveur web.
+
+ -h|--help
+ Affiche ce message.
+EOF
+ exit
+ shift;;
+
+ --)
+ shift
+ break;;
+ esac
+done
+
+CMD="$1"
+
+[ "$CMD" = "" ] && {
+ CMD="ui"
+}
+
+PROJECT="$2"
+
+[ "$PROJECT" = "" ] && PROJECT="1"
+
+export GARRADIN_STANDALONE="$PROJECT"
+
+[ $VERBOSE = 1 ] && {
+ php -S ${ADDRESS}:${PORT} -t ${ROOT} -d variables_order=EGPCS ${ROUTER} &
+} || {
+ php -S ${ADDRESS}:${PORT} -t ${ROOT} -d variables_order=EGPCS ${ROUTER} > /dev/null 2>&1 &
+}
+
+php_pid=$!
+sleep .5
+
+[ "$CMD" = "ui" ] && {
+ URL="http://${ADDRESS}:${PORT}/"
+ [ "$DISPLAY" != "" ] && {
+ x-www-browser ${URL} &
+ } || {
+ www-browser ${URL} &
+ }
+
+ wait $!
+ kill $php_pid
+} || {
+ wait $php_pid
+}